print('统计字符数：wc.exe -c 绝对路径')
print('统计单词数：wc.exe -w 绝对路径')
print('统计句子数：wc.exe -sen 绝对路径')
print('统计注释行数：wc.exe -note 绝对路径')
print('统计空行数：wc.exe -emp 绝对路径')
print('统计代码行数：wc.exe -code 绝对路径')
while True:  # 设置循环，保证能一直输入
    a, b, name = input('输入指令：').split()  # 读取输入并用‘ ’进行分割
    s = 0  # 初始化计数
    if a == 'wc.exe':
        if b == '-c':  # 统计字符数
            filename = open(name, 'r')  # 打开文档
            filetexts = filename.read()  # 读取文档内容，并保存到filetexts中
            for filetext in filetexts:  #历遍filetexts中的每一个项
                if (filetext == '\n' or filetext == ' '):   #当前位置不为空就是字符
                    continue
                else:
                    s = s + 1  # s用于统计字符个数
            print('一共有%d个字符' % s)
        if b == '-w':   #统计单词数
            filename = open(name, 'r')
            filetexts = filename.read()
            words = filetexts.split()   #将filetexts的内容用‘ ’进行分割存入words中
            num = len(words)        #words的长度就是单词的个数
            print('一共有'+ str(num) + '个单词')
        if b == '-sen':
            filename = open(name, 'r')
            filetexts = filename.read()
            for filetext in filetexts:
                if (filetext == '.' or filetext == '!' or filetext == '?' or filetext == ','):  # 判断句子是否完结
                    s = s + 1   #以上述符号结尾，句子数加一
            print('一共有%d个句子' %s)
        if b == '-note':
            filename = open(name, 'r')
            filetexts = filename.read()
            for filetext in filetexts:
                if filetext == '#':  #根据注释符号“#”判断是否为注释行
                    s = s + 1
            print('一共有%d个注释行' %s)
        if b == '-emp':
            filename = open(name, 'r')
            for filetext in filename.readlines():
                filetext = filetext.strip()  # 移除每行头尾的空白部分
                if filetext == "": #移除完了为空白即为空行
                    s = s + 1
            print('一共有%d个空行' %s)
        if b == '-code':
            filename = open(name, 'r')
            t = len(open(name, 'r').readlines())  #t用于统计总行数
            filename = open(name, 'r')
            for filetext in filename.readlines():   #历遍每一行
                filetext = filetext.strip()     #删除每行的首位空白部分
                if filetext == "":
                    s = s + 1   #统计空行
            filename = open(name, 'r')
            filetexts = filename.read()         #读取存储到filetexts中
            for filetext in filetexts:
                if filetext == '#':
                    s = s + 1   #统计空行与注释行
            t = t - s           #代码行等于总行数减去空行与注释行之和
            print('一共有%d个代码行' %t)
